home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / shufl1 / sound1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  10.3 KB  |  348 lines

  1. VERSION 2.00
  2. Begin Form Sound1 
  3.    Caption         =   "System Sound Shuffler"
  4.    ClientHeight    =   3870
  5.    ClientLeft      =   1185
  6.    ClientTop       =   1545
  7.    ClientWidth     =   7890
  8.    Height          =   4275
  9.    Icon            =   SOUND1.FRX:0000
  10.    Left            =   1125
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   3870
  14.    ScaleWidth      =   7890
  15.    Top             =   1200
  16.    Width           =   8010
  17.    Begin CommonDialog CMDialog1 
  18.       Left            =   5400
  19.       Top             =   4320
  20.    End
  21.    Begin CommandButton Command1 
  22.       Caption         =   "E&xit"
  23.       Height          =   375
  24.       Index           =   5
  25.       Left            =   6300
  26.       TabIndex        =   14
  27.       Top             =   3120
  28.       Width           =   1335
  29.    End
  30.    Begin CommandButton Command1 
  31.       Caption         =   "Shu&ffle"
  32.       Height          =   375
  33.       Index           =   4
  34.       Left            =   6300
  35.       TabIndex        =   13
  36.       Top             =   2580
  37.       Width           =   1335
  38.    End
  39.    Begin CommandButton Command1 
  40.       Caption         =   "&Set Current"
  41.       Height          =   375
  42.       Index           =   3
  43.       Left            =   6300
  44.       TabIndex        =   12
  45.       Top             =   2040
  46.       Width           =   1335
  47.    End
  48.    Begin CommandButton Command1 
  49.       Caption         =   "&Play File"
  50.       Height          =   375
  51.       Index           =   2
  52.       Left            =   6300
  53.       TabIndex        =   11
  54.       Top             =   1500
  55.       Width           =   1335
  56.    End
  57.    Begin CommandButton Command1 
  58.       Caption         =   "&Remove File"
  59.       Height          =   375
  60.       Index           =   1
  61.       Left            =   6300
  62.       TabIndex        =   10
  63.       Top             =   960
  64.       Width           =   1335
  65.    End
  66.    Begin CommandButton Command1 
  67.       Caption         =   "&Add File"
  68.       Height          =   375
  69.       Index           =   0
  70.       Left            =   6300
  71.       TabIndex        =   9
  72.       Top             =   420
  73.       Width           =   1335
  74.    End
  75.    Begin PictureBox Picture3 
  76.       BackColor       =   &H00C0C0C0&
  77.       BorderStyle     =   0  'None
  78.       Height          =   3195
  79.       Left            =   240
  80.       ScaleHeight     =   3195
  81.       ScaleWidth      =   5775
  82.       TabIndex        =   0
  83.       Top             =   360
  84.       Width           =   5775
  85.       Begin CheckBox chEnabled 
  86.          BackColor       =   &H00C0C0C0&
  87.          Caption         =   "Shuffling E&nabled"
  88.          Height          =   255
  89.          Left            =   240
  90.          TabIndex        =   6
  91.          Top             =   2760
  92.          Width           =   2775
  93.       End
  94.       Begin ListBox lbFiles 
  95.          Height          =   1395
  96.          Left            =   1020
  97.          TabIndex        =   4
  98.          Top             =   1140
  99.          Width           =   4455
  100.       End
  101.       Begin ComboBox coEvents 
  102.          Height          =   300
  103.          Left            =   1020
  104.          Style           =   2  'Dropdown List
  105.          TabIndex        =   2
  106.          Top             =   240
  107.          Width           =   3315
  108.       End
  109.       Begin Label Label1 
  110.          BackColor       =   &H00C0C0C0&
  111.          Caption         =   "Shuffle &Files:"
  112.          Height          =   435
  113.          Index           =   1
  114.          Left            =   240
  115.          TabIndex        =   3
  116.          Top             =   1140
  117.          Width           =   735
  118.       End
  119.       Begin Label laSound 
  120.          BackColor       =   &H00C0C0C0&
  121.          Height          =   255
  122.          Left            =   1620
  123.          TabIndex        =   8
  124.          Top             =   720
  125.          Width           =   3975
  126.       End
  127.       Begin Label Label2 
  128.          BackColor       =   &H00C0C0C0&
  129.          Caption         =   "Current Sound:"
  130.          Height          =   255
  131.          Left            =   240
  132.          TabIndex        =   7
  133.          Top             =   720
  134.          Width           =   1335
  135.       End
  136.       Begin Label Label1 
  137.          BackColor       =   &H00C0C0C0&
  138.          Caption         =   "&Event:"
  139.          Height          =   255
  140.          Index           =   0
  141.          Left            =   240
  142.          TabIndex        =   1
  143.          Top             =   300
  144.          Width           =   615
  145.       End
  146.    End
  147.    Begin PictureBox Picture1 
  148.       BorderStyle     =   0  'None
  149.       Height          =   255
  150.       Left            =   0
  151.       Picture         =   SOUND1.FRX:0302
  152.       ScaleHeight     =   255
  153.       ScaleWidth      =   375
  154.       TabIndex        =   5
  155.       Top             =   0
  156.       Visible         =   0   'False
  157.       Width           =   375
  158.    End
  159. Dim NewFlag As Integer
  160. Sub chEnabled_Click ()
  161.     If NewFlag Then Exit Sub
  162.     x% = chEnabled.Value
  163.     Key$ = coEvents.Text
  164.     Res% = WritePrivateProfileString("Enabled", Key$, Str$(x%), "Shuffle.ini")
  165. End Sub
  166. Sub coEvents_Click ()
  167.     UpdateFiles
  168.     PassedString$ = Space$(gSize)
  169.     Key$ = coEvents.Text
  170.     a% = GetPrivateProfileString("Enabled", Key$, "", PassedString$, gSize, "Shuffle.ini")
  171.     temp$ = Left$(PassedString$, a%)
  172.     NewFlag = True
  173.     If temp$ = "1" Then
  174.     chEnabled.Value = 1
  175.     Else
  176.     chEnabled.Value = 0
  177.     End If
  178.     NewFlag = False
  179. End Sub
  180. Sub Command1_Click (Index As Integer)
  181. Select Case Index
  182. Case 0      'Add File
  183.     CMDialog1.DefaultExt = "WAV"
  184.     CMDialog1.DialogTitle = "Select Sound File"
  185.     CMDialog1.FileName = ""
  186.     CMDialog1.Filter = "Sound (*.wav)|*.wav"
  187.     CMDialog1.FilterIndex = 1
  188.     CMDialog1.Flags = OFN_FILEMUSTEXIST Or OFN_NOCHANGEDIR
  189.     If gsInitDir <> "" Then CMDialog1.InitDir = gsInitDir
  190.     CMDialog1.Action = 1
  191.     FName$ = CMDialog1.FileName
  192.     FTitle$ = CMDialog1.FileTitle
  193.     If FName$ <> "" Then
  194.     gsInitDir = Left$(FName$, Len(FName$) - Len(FTitle$) - 1)
  195.     If Len(gsInitDir) < 3 Then gsInitDir = gsInitDir + "\"
  196.     IniApp$ = coEvents.Text
  197.     x% = InStr(FTitle$, ".")
  198.     If x% <> 0 Then
  199.         Key$ = Mid$(FTitle$, 1, x% - 1)
  200.     Else
  201.         Key$ = FTitle$
  202.     End If
  203.     a% = WritePrivateProfileString(IniApp$, Key$, FName$, "Shuffle.ini")
  204.     UpdateFiles
  205.     End If
  206. Case 1      'Remove a file
  207.     If lbFiles.ListIndex = -1 Then
  208.     Msg$ = "Select a sound file to remove"
  209.     MsgType% = MB_ICONASTERISK
  210.     Title$ = "System Sound Shuffler"
  211.     sMsgBox Msg$, MsgType%, Title$
  212.     Exit Sub
  213.     End If
  214.     FName$ = lbFiles.Text
  215.     Msg$ = "Are you sure you want to remove " + FName$ + "?"
  216.     Title$ = "System Sound Shuffler"
  217.     Res% = fMsgBox(Msg$, MB_ICONQUESTION + 3, Title$)
  218.     If Res% = 6 Then
  219.     LastNdx% = 1
  220.     NextNdx% = 1
  221.     Cut% = 0
  222.     While NextNdx% <> 0
  223.         NextNdx% = InStr(LastNdx%, FName$, "\")
  224.         If NextNdx% <> 0 Then
  225.         Cut% = NextNdx%
  226.         End If
  227.         LastNdx% = NextNdx% + 1
  228.     Wend
  229.     If Cut% <> 0 Then
  230.         FName$ = Mid$(FName$, Cut% + 1)
  231.     End If
  232.     x% = InStr(FName$, ".")
  233.     If x% Then FName$ = Left$(FName$, x% - 1)
  234.     IniApp$ = coEvents.Text
  235.     Res% = KillIniKey(IniApp$, FName$, 0&, "Shuffle.ini")
  236.     UpdateFiles
  237.     End If
  238. Case 2      'Play selected file
  239.     If lbFiles.ListIndex = -1 Then
  240.     Msg$ = "Select a sound file to play"
  241.     sMsgBox Msg$, MB_ICONASTERISK, "System Sound Shuffler"
  242.     Exit Sub
  243.     End If
  244.     FName$ = lbFiles.Text
  245.     Sound1.MousePointer = 11
  246.     sndPlaySound FName$, 2
  247.     Sound1.MousePointer = 0
  248. Case 3      'Set Current
  249.     MakeFileCurrent
  250. Case 4      'Randomize
  251.     MousePointer = 11
  252.     Msg1.Show 0
  253.     Junk% = DoEvents()
  254.     Shuffle
  255.     WinKey$ = gEventsArray(coEvents.ListIndex, 1)
  256.     PassedString$ = Space$(gSize)
  257.     a% = GetProfileString("Sounds", WinKey$, "[None]", PassedString$, gSize)
  258.     x% = InStr(PassedString$, ",")
  259.     If x% Then
  260.     CurrentSound$ = Left$(PassedString$, x% - 1)
  261.     Else
  262.     CurrentSound$ = Left$(PassedString$, a%)
  263.     End If
  264.     laSound.Caption = CurrentSound$
  265.     Unload Msg1
  266.     MousePointer = 0
  267. Case 5   'Done
  268.     End
  269. End Select
  270. End Sub
  271. Sub Form_Load ()
  272.     Screen.MousePointer = 11
  273.     WindowState = 0
  274.     For x% = 1 To giNumEvents
  275.     temp$ = gEventsArray(x% - 1, 0)
  276.     coEvents.AddItem temp$
  277.     Next
  278.     coEvents.ListIndex = 0
  279.     AutoRedraw = True
  280.     ShadeForm Sound1
  281.     AutoRedraw = False
  282.     MakeBevel Picture3
  283.     Screen.MousePointer = 0
  284. End Sub
  285. Sub lbFiles_DblClick ()
  286.     If lbFiles.ListIndex = -1 Then
  287.     Msg$ = "Select a sound file to play"
  288.     sMsgBox Msg$, MB_ICONASTERISK, "System Sound Shuffler"
  289.     Exit Sub
  290.     End If
  291.     FName$ = lbFiles.Text
  292.     Sound1.MousePointer = 11
  293.     sndPlaySound FName$, 2
  294.     Sound1.MousePointer = 0
  295. End Sub
  296. Sub MakeFileCurrent ()
  297.     If lbFiles.ListIndex = -1 Then
  298.     Msg$ = "Select a sound file to make current"
  299.     sMsgBox Msg$, MB_ICONASTERISK, "System Sound Shuffler"
  300.     Exit Sub
  301.     End If
  302.     FName$ = lbFiles.Text
  303.     Event$ = coEvents.Text
  304.     WinKey$ = gEventsArray(coEvents.ListIndex, 1)
  305.     a% = WriteProfileString("Sounds", WinKey$, FName$ + "," + Event$)
  306.     laSound.Caption = FName$
  307. End Sub
  308. Sub UpdateFiles ()
  309. 'Get sound files for this event
  310.     IniApp$ = coEvents.Text
  311.     WinKey$ = gEventsArray(coEvents.ListIndex, 1)
  312.     While lbFiles.ListCount
  313.     lbFiles.RemoveItem 0
  314.     Wend
  315.     PassedString$ = Space$(gSize)
  316. 'First get current sound for this event
  317.     a% = GetProfileString("Sounds", WinKey$, "[None]", PassedString$, gSize)
  318.     x% = InStr(PassedString$, ",")
  319.     If x% Then
  320.     CurrentSound$ = Left$(PassedString$, x% - 1)
  321.     Else
  322.     CurrentSound$ = Left$(PassedString$, a%)
  323.     End If
  324.     laSound.Caption = CurrentSound$
  325.     PassedString$ = Space$(gSize)
  326. 'Now get list of shuffle files for this event
  327.     a% = GetIniSections(IniApp$, 0&, "", PassedString$, gSize, "Shuffle.ini")
  328.     If a% = 0 Then Exit Sub   'there aren't any files
  329.     Null$ = Chr$(0)
  330.     Sections$ = Left$(PassedString$, a%)
  331.     LastNdx = 0
  332.     NextNdx = 1
  333.     Counter = 0
  334. 'Files are separated by nulls so parse them
  335.     While NextNdx > 0
  336.     NextNdx = InStr(LastNdx + 1, Sections$, Null$)
  337.     If NextNdx <> 0 Then
  338.         Cut = NextNdx - LastNdx - 1
  339.         temp$ = Mid$(Sections$, LastNdx + 1, Cut)
  340.         PassedString$ = Space$(gSize)
  341.         a% = GetPrivateProfileString(IniApp$, temp$, "", PassedString$, gSize, "Shuffle.ini")
  342.         temp$ = Left$(PassedString$, a%)
  343.         lbFiles.AddItem temp$
  344.     End If
  345.     LastNdx = NextNdx
  346.     Wend
  347. End Sub
  348.